<?php $this->load->view('common/head');?>

<?php $this->load->view('common/header');?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar');?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs');?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set');?>
                <div class="row">
                    <div class="col-sm-22 widget-container-col ui-sortable" id="widget-container-col-10">
                        <div class="widget-box ui-sortable-handle" id="widget-box-10">
                            <div class="widget-header widget-header-small">
                                <h5 class="widget-title smaller">单页信息</h5>
                            </div>
                            <div class="widget-body">
                                <div class="widget-main padding-6" style="overflow: hidden">
                                    <div class="tab-content">
                                        <div id="home" class="tab-pane active">
                                            <div class="col-xs-12">
                                                <!-- PAGE CONTENT BEGINS -->
                                                <form class="form-horizontal" action="<?php echo site_url(X_URL.'article/update');?>" method="post" id="from1" >
                                                    <?php echo csrf_hidden();?>
                                                    <input type="hidden" name="article_id" value="<?php if(!empty($article_id)){  echo $article_id;}?>">
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 单页标题 </label>
                                                        <div class="col-sm-9">
                                                            <input type="text" name="article_title" class="rcol-xs-10 col-sm-5" value="<?php if(isset($article)){ echo $article["article_title"];}?>">
                                                            <input type="hidden" name="article_id" value="<?php if(isset($article)){ echo $article["article_id"];}?>">
                                                            <span class="help-inline col-xs-12 col-sm-7">
                											     <span class="middle">请填写单页标题</span>
                											</span>
                                                        </div>
                                                    </div>

                                                    <div class="space-4"></div>
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-4"> 所属分类 </label>
                                                        <div class="col-sm-2" style="width: 12%">
                                                            <select id="article_category" name="article_category" class="select2">
                                                            <option value="0">请选择分类</option>
                                                            <?php if(isset($category) && !empty($category)){ ?>
                                                                <?php foreach ($category as $key =>$val ) { ?>
                                                                    <option value="<?php echo $val['id'];?>" <?php if(isset($article) && $article['article_category'] == $val['id']){?>selected="selected"<?php } ?>
                                                                    ><?php echo $val['category_name'];?></option>
                                                                <?php }?>
                                                            <?php }?>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-4">缩略图 </label>
                                                        <div class="col-sm-6">
                                                            <div class="file-loading">
                                                                <input id="kv-explorer" name="pic[]" type="file" accept="image/*" multiple>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <input type="hidden" id="access_key" name="access_key" value="<?php if(!empty($article['article_cover'])){  echo $article['article_cover'];}?>">
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-7"> 单页介绍 </label>
                                                        <div class="col-sm-9">
                                                            <textarea name="article_memo" id="article_memo" placeholder="单页介绍"  class="col-xs-10 col-sm-10"  rows="5"><?php if(!empty($article['article_memo'])){  echo $article['article_memo'];}?></textarea>
                                                            <span class="help-inline col-xs-12 col-sm-7">
                                                            <span class="middle"></span>
                                                        </span>
                                                        </div>
                                                    </div>
                                                    <div class="space-4"></div>
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-8">
                                                            单页详情 </label>
                                                        <div class="col-sm-9">
                                                            <textarea name="article_content" id="article_content" style="width:85%;height:400px;visibility:hidden;"><?php if(!empty($article['article_content'])){  echo $article['article_content'];}?></textarea>
                                                        </div>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 排序 </label>
                                                        <div class="col-sm-9">
                                                            <input type="text" name="order" class="rcol-xs-10 col-sm-5" value="<?php if(isset($article)){ echo $article["order"];}?>">
                                                            <span class="help-inline col-xs-12 col-sm-7">
                											     <span class="middle">请填写排序id</span>
                											</span>
                                                        </div>
                                                    </div>
                                                    <div class="space-4"></div>
                                                    <div class="col-md-offset-2 col-md-9">
                                                        <button class="btn btn-info" type="submit" id="subForm1">
                                                            <i class="icon-ok bigger-110"></i>
                                                            提交
                                                        </button>

                                                        &nbsp; &nbsp; &nbsp;
                                                        <button class="btn" type="reset">
                                                            <i class="icon-undo bigger-110"></i>
                                                            重置
                                                        </button>
                                                    </div>

                                                </form>
                                                <!-- PAGE CONTENT ENDS -->
                                            </div><!-- /.col -->
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /section:settings.box -->
                <div class="row">

                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <?php $this->load->view('common/footer');?>
</div><!-- /.main-container -->
<?php $this->load->view('common/footerjs');?>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(function () {
        var article_id = "<?php if(!empty($article_id)){  echo $article_id;}?>";
        var good_select2 = $("#article_category").select2();
        $("#web_category").on("select2:select", function(e){
            console.log($(this).val());
            var web_id = $(this).val();
            if (web_id > 0) {
                $.ajax({
                    method: "GET",
                    url: baseurl+'index.php/area/get_good_category',
                    data: {web_id:web_id}
                }).done(function(data){
                    // console.log(data);
                    $("#article_category").html(data);
                    good_select2.val(0).trigger("change");
                })
            } else {
                $("#article_category").html('<option selected="selected" value="0">请选择二级频道</option>');
                good_select2.val(0).trigger("change");
            }
        });
        
        $("#tabs").tabs();
        var editor = KindEditor.create('textarea[name="article_content"]', {
            uploadJson: baseurl+'index.php/manage/articleimg/editor_upload_img?type=articles&article_id='+article_id,
            fileManagerJson: '__PUBLIC__/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            afterBlur: function () {
                this.sync();
            }
        });
       
        $("#subForm1").click(function () {
           
            
            var article_title = $("#article_title").val();
            if (article_title == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "单页标题必须填写。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            $("#from1").submit();
        });

        $("#subForm2").click(function () {
            $("#from2").submit();
        });


        $("#subForm3").click(function () {
            $("#from3").submit();
        });

        $("#subForm4").click(function () {
            $("#from4").submit();
        });
        var picpath = <?php echo $pic_path;?>;
        var piccon = <?php echo $pic_con;?>;
        $(document).ready(function () {
            $("#kv-explorer").fileinput({
                language: 'zh',
                uploadAsync: false, //设置上传同步异步 此为同步
                dropZoneEnabled: false,
                showCaption: false,//是否显示标题
                showRemove:false,
                'theme': 'explorer-fa',
                'uploadUrl': baseurl+'index.php/manage/pubfun/upload_article_img',
                overwriteInitial: false,
                initialPreviewAsData: true,
                initialPreviewFileType: 'image',
                initialPreview:picpath, //要显示的图片的路径
                initialPreviewConfig:piccon
            });
            $("#kv-explorer").on("filebatchuploadsuccess", function (event, data) {
                var rst = data.response;
                var access_key = rst.access_key;
                $("#access_key").val(access_key);
            });
        });
    });
</script>
</body>
</html>
